/*
 * 项目页面JS验证公共库
 */
function notNull(obj) {
	var val = $.trim((obj || {}).value);
	//obj.value = val; // 这样做会使光标位置发生改变
	if (val.length <= 0) {
		if (obj.error) return;
		obj.style.border="2px solid red";
		var span = document.createElement("span");
		//span.setAttribute("style", "font-size:12px;color:red;padding-left:10px;");
		span.style.fontSize='12px';
		span.style.paddingLeft="10px";
		span.style.color="red";
		var node = document.createTextNode("该字段不能为空！");
		span.appendChild(node);
		obj.parentNode.insertBefore(span, obj.nextSibling);
		obj.error = 1;
		++window.error;
	}
	else {
		if (!obj.error) return;
		obj.style.border="1px solid #DDD";
		obj.parentNode.removeChild(obj.nextSibling);
		obj.error = undefined;
		--window.error;
	}
}
function email(val) {
	val = val || "";
	return val.match(/^\w+@.+\.\w$/);
}
(function(window) {
	// error count
  	window.error = 0;
  	var elements = document.forms[0].elements;
  	for (var i = 0; i < elements.length; i++) {
  		var ele = elements[i];
  		if (ele.getAttribute("alt") == "notNull") {
  			ele.onblur = function() {
  				notNull(this);
  			}
  		}
  	}
  	document.forms[0].onsubmit = function() {
  		for (var i = 0; i < elements.length; i++) {
	  		var ele = elements[i];
	  		if (ele.getAttribute("alt") == "notNull") {
	  			ele.onblur();
	  		}
	  	}
  		if (window.error >= 1) {
  			return false;
  		}
  		return true;
  	}
})(window);




